
(function(window, undefined) {
    let t = null
    $.fn.lazyLoad = function() 
    {
      let _this = this  // jq对象
      // console.log(this)
      function lazyLoad() 
      {
        if (t) clearTimeout(t)
        t = setTimeout(() => {
        //    2.1 获取可视区高度：窗口高度 + 滚动高度
          let windowH = window.innerHeight || document.documentElement.clientHeight
          let scrollH = document.body.scrollTop || document.documentElement.scrollTop
          let showH = windowH + scrollH
        //    2.2 获取所有图片
          let imgs = _this
        //    2.3 遍历  判断  2.2 是否小于  2.1 
          for (let i=0; i<imgs.length; i++)
          {
              if (imgs[i].offsetTop < showH) {
                imgs[i].src = imgs[i].getAttribute('data-src')
              }
          }
        }, 100)
      }
    
      lazyLoad()
      window.onscroll = lazyLoad
    }
    
  })(window)